package com.ruibang.glass.produce.controller.system;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.frequencycontrol.annotation.FrequencyControl;
import com.ruibang.glass.produce.domain.req.HotSingleBoardDefectReq;
import com.ruibang.glass.produce.domain.req.StirringRodTrendChart;
import com.ruibang.glass.produce.domain.resp.HotSingleBoardDefectSummary;
import com.ruibang.glass.produce.domain.resp.HotSingleBoardDefectTrendChart;
import com.ruibang.glass.produce.domain.resp.HotSingleBoardFlowTrendChart;
import com.ruibang.glass.produce.service.HotSingleBoardDefectService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;


@Api(tags = "热端单板缺陷控制器(气泡-结石)")
@RestController
@RequestMapping("/api/glass/produce/hotSingleBoardDefect")
public class HotSingleBoardDefectController {

    @Autowired
    private HotSingleBoardDefectService hotSingleBoardDefectService;

    @PostMapping("/defectSummary")
    @ApiOperation(value = "缺陷汇总", notes = "缺陷汇总")
    public ResultBody<HotSingleBoardDefectSummary> defectSummary(@RequestBody @Valid HotSingleBoardDefectReq hotSingleBoardDefectReq) {
        return ResultBody.success(hotSingleBoardDefectService.defectSummary(hotSingleBoardDefectReq));
    }

    @PostMapping("/defectQuantityTrendChart")
    @ApiOperation(value = "缺陷数量趋势图", notes = "缺陷数量趋势图")
    public ResultBody<HotSingleBoardDefectTrendChart> defectQuantityTrendChart(@RequestBody @Valid HotSingleBoardDefectReq hotSingleBoardDefectReq) {
        return ResultBody.success(hotSingleBoardDefectService.defectQuantityTrendChart(hotSingleBoardDefectReq));
    }

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页查询缺陷数据", notes = "分页查询缺陷数据")
    public ResultBody<IPage<HotSingleBoardDefectSummary>> pageQuery(@RequestBody @Valid HotSingleBoardDefectReq hotSingleBoardDefectReq) {
        return ResultBody.success(hotSingleBoardDefectService.pageQuery(hotSingleBoardDefectReq));
    }

    @PostMapping("/flowTrendChart")
    @ApiOperation(value = "流量趋势图", notes = "流量趋势图")
    public ResultBody<List<HotSingleBoardFlowTrendChart>> flowTrendChart(@RequestBody HotSingleBoardDefectReq hotSingleBoardDefectReq) {
        return ResultBody.success(hotSingleBoardDefectService.flowTrendChart(hotSingleBoardDefectReq));
    }

    @PostMapping("/stirringRodTrendChart")
    @ApiOperation(value = "搅拌棒趋势图", notes = "搅拌棒趋势图")
    public ResultBody<List<StirringRodTrendChart>> stirringRodTrendChart(@RequestBody HotSingleBoardDefectReq hotSingleBoardDefectReq) {
        return ResultBody.success(hotSingleBoardDefectService.stirringRodTrendChart(hotSingleBoardDefectReq));
    }

    @PostMapping("/export")
    @ApiOperation(value = "缺陷数据导出", notes = "缺陷数据导出")
    @FrequencyControl(time = 15, count = 2, target = FrequencyControl.Target.IP)
    @FrequencyControl(time = 30, count = 3, target = FrequencyControl.Target.IP)
    public void export(@RequestBody @Valid HotSingleBoardDefectReq hotSingleBoardDefectReq, HttpServletResponse response) {
        hotSingleBoardDefectService.export(hotSingleBoardDefectReq,response);
    }
}
